public class Demo6 {
    static int result = 0;
    static Object locker = new Object();
    static Object locker2 = new Object();
    public static void add(int a){
            result++;
    }
    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(()->{
            synchronized(locker){
                for (int i = 0; i < 50000; i++) {
                    add(result);
                }
            }
        });
        Thread t2 = new Thread(()->{
                synchronized(locker2){
                    for (int i = 0; i < 50000; i++) {
                        add(result);
                    };
                }
        });
        t1.start();
        t2.start();
        Thread.sleep(100);
        System.out.println( result);
    }
}
